package test3_10;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Test4_twoArraysAreSwappedEndToEnd {
    public static void main(String[] args) {
        /*
        两个数组首尾交换 {1,2,3,4},{5,6,7,8} -> {8,7,6,5},{4,3,2,1}
         */
        int[] array1 = {1, 2, 3, 4};
        int[] array2 = {5, 6, 7, 8};
        int t = 0;
        for (int i = 0; i < array1.length / 2; i++) {
            t = array1[i];
            array1[i] = array1[array1.length - i - 1];
            array1[array1.length - i - 1] = t;
        }

        for (int i = 0; i < array2.length / 2; i++) {
            t = array2[i];
            array2[i] = array2[array2.length - i - 1];
            array2[array2.length - i - 1] = t;
        }

        for (int i = 0; i < array1.length; i++) {
            t = array1[i];
            array1[i] = array2[i];
            array2[i] = t;
        }

        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));
    }
}
